Using the command line or a code editor (i.e., VS Code, Cursor, Positron, etc.), locate or create a project directory to use, preferable one that is not being synced to the cloud via OneDrive, iCloud, etc.
macOS and Linux via Terminal
cd ~/Desktopmkdir uv-practicecd uv-practice
Windows via PowerShell
cd Desktopmkdir uv-practicecd uv-practice
Dragging a folder from your finder/file explorer and dropping it into the terminal/shell will paste its file path
This creates a pyproject.toml file with metadata about the project and a hidden .python-version file that specifies the default version of Python for the project.
It also creates main.py and README.md files that you can use or delete.
Install libraries
With the project environment initialized, you can now install libraries. For example, to install the Pandas library, run:
uv add pandas
This installs Pandas, and any dependencies, and creates both a uv.lock file that keeps track of the versions of the libraries you’ve installed and a hidden .venv reproducible environment folder that serves as the project library.
Whenever you install new libraries, the uv.lock file is automatically updated.
With packages now installed uv can be used to run code in your environment. No need to activate/deactivate your venv — uv run does it. If the .venv somehow gets deleted uv will check prior to running and re-initailize it.
uv run main.py
import pandas as pdimport matplotlib.pyplot as plt# --- USU Color Scheme ---usu_colors = ['#003366','#9D9D9D','#6699CC', '#0055A4' ]# Load customer data and establish region countscustomer_data = pd.read_csv('../data/customer_data.csv')region_counts = customer_data['region'].value_counts()#Plot regional customer distributionsfig, ax = plt.subplots(figsize=(8, 8)) region_counts.plot.pie( ax=ax, autopct='%1.1f%%', startangle=90, colors=usu_colors[:len(region_counts)])ax.set_title('Customer Region Distribution', fontsize=16, color='#003366', fontweight='bold')ax.set_ylabel('')plt.show()
Run Code In Your Environment
Other Useful Features
uv offers several powerful commands to streamline project management and collaboration.
Auto-Install on Run If you’re starting with an existing project, uv run automatically installs any missing libraries from the uv.lock file before executing your code.
# No need to run 'uv sync' first!uv run python your_script.py
Export for Compatibility To share your project with someone using a different tool (like pip), you can export your environment’s dependencies into standard formats.